package org.megha.blog.example.part15;

import junit.framework.TestCase;

public class CounterTest extends TestCase {

	private Counter counter;

	public CounterTest() {
		System.out.println("creating CounterTest");
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		counter = new Counter();
		System.out.println("setup");
	}

	@Override
	protected void tearDown() throws Exception {
		System.out.println("teardown");
		super.tearDown();
	}

	public void testDefaultValueOfCounterIsZero() {
		System.out.println("test #1");
		assertEquals(0, counter.getCount());
	}

	public void testIncrementingIncreasesCountByOne() {
		System.out.println("test #2");
		counter.increment();
		assertEquals(1, counter.getCount());
	}

	public void testMultipleIncrements() {
		System.out.println("test #3");
		for (int i = 0; i < 10; i++) {
			counter.increment();
			assertEquals(i + 1, counter.getCount());
		}
	}

	public void testResetingResetsCountToSpecifiedValue() {
		System.out.println("test #4");
		counter.resetCount(5);
		assertEquals(5, counter.getCount());
		counter.increment();
		assertEquals(6, counter.getCount());
		counter.resetCount(100);
		assertEquals(100, counter.getCount());
	}
}
